import React, { Component } from 'react'
import {HashRouter as Router, Link, Route, Switch} from 'react-router-dom'
import CacheRoute, { CacheSwitch } from 'react-router-cache-route'

class Index extends Component{
  constructor(props){
    super(props)
    console.log('构造index组件');
  }
  render(){
    return <h1>首页</h1>
  }
}
class User extends Component {
  constructor(props){
    super(props)
    console.log('构造User组件');
  }
  render(){
    return <h1>用户</h1>
  }
}
export default class App extends Component {
  render() {
    return (
      <div>
        <div className="my-router">
          <Router>
            <Link to='/index'>首页</Link>
            <Link to='/user'>用户</Link>
            <CacheSwitch>
              <CacheRoute path='/index' component={Index}></CacheRoute>
              <Route path='/user' component={User}></Route>
            </CacheSwitch>
          </Router>
        </div>
      </div>
    )
  }
}
